package qj.ui.console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import qj.ui.IConsole;

public class SystemConsole implements IConsole {

	public void println(String s) {
		System.out.println(s);
	}
	
	public void writeln(String s) {
		System.out.println(s);
	}
	
    public static final BufferedReader READER = new BufferedReader( new InputStreamReader(System.in) );
	public String readLine() {
		try {
			return READER.readLine();
		} catch (IOException e) {
			return null;
		}
	}

	public String readLineUntil(String limit) {
		StringBuffer sb = new StringBuffer();
		String readLine;
		boolean first = true;
		while (! (readLine = readLine()).equals(limit)) {
			if (!first)
				sb.append("\n");
			sb.append(readLine);
			first = false;
		}
			
		return sb.toString();
	}

	public String readLineUntilDot() {
		return readLineUntil(".");
	}

	public String readLineUntilDot(String prompt1) {
		System.out.println(prompt1 + " (end by .)");
		return readLineUntilDot();
	}

	public String readLineUntilDot(String prompt1, String prompt2) {
		String ret = readLine(prompt1);
		
		if (ret.length() > 0) {
			return ret;
		} else {
			return readLineUntilDot(prompt2);
		}
	}

	public String readLine(String str) {
		System.out.print(str);
		return readLine();
	}
	
}
